﻿package plugin.instances.game
{
    import com.core.*;
    import flash.events.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import plugin.union.*;
    import uiresource.instances.ui.*;
    import view.message.*;
    import view.mornExtends.*;

    public class UnionEmsGame extends UnionEmsUI implements IInstance
    {
        private var transTimeDis:int = 0;
        private var qzTimeDis:int = 0;
        private var timer:int = 0;
        private var timeEnd:int = 0;
        private var emsMsg:Object;

        public function UnionEmsGame()
        {
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_8:Object = null;
            var _loc_9:Object = null;
            var _loc_10:Array = null;
            var _loc_11:Array = null;
            var _loc_12:Array = null;
            var _loc_13:Date = null;
            var _loc_14:Date = null;
            var _loc_15:Date = null;
            var _loc_16:Number = NaN;
            if (this.emsMsg == null)
            {
                _loc_8 = ConfigDictionary.data.gameactive;
                for each (_loc_9 in _loc_8)
                {
                    
                    if (_loc_9.dietype == 3)
                    {
                        this.emsMsg = _loc_9;
                    }
                }
            }
            var _loc_3:* = this.emsMsg.time;
            var _loc_4:* = int((ModelProxy.getValue("data", "servertime") + Number(getTimer())) / 1000);
            if (_loc_3 != null && _loc_3 != "")
            {
                _loc_10 = _loc_3.split("-");
                _loc_11 = (_loc_10[0] as String).split("#");
                _loc_12 = (_loc_10[1] as String).split("#");
                _loc_13 = new Date();
                _loc_14 = new Date(_loc_13.fullYear, _loc_13.month, _loc_13.date, int(_loc_11[0]), int(_loc_11[1]), 0, 0);
                _loc_15 = new Date(_loc_13.fullYear, _loc_13.month, _loc_13.date, int(_loc_12[0]), int(_loc_12[1]), 0, 0);
                if (_loc_14.time > _loc_15.time)
                {
                    _loc_15.time = _loc_15.time + 86400000;
                }
                _loc_16 = _loc_15.time / 1000;
                this.timeEnd = _loc_16 - _loc_4;
                if (this.timer > 0)
                {
                    clearInterval(this.timer);
                }
                this.timer = setInterval(this.timeCheck, 1000);
            }
            var _loc_5:* = ModelProxy.getValue("data", "unionInfo");
            var _loc_6:* = ModelProxy.getValue("data", "unionInfo").unionLevel;
            var _loc_7:* = ConfigDictionary.data.unionEms;
            txt_level.text = _loc_6 + "级囚犯";
            ModelProxy.change("zone", "paoCheck", 1);
            this.showItem("1/4");
            shuoming.toolTip = "1.在行会押送犯人周围可以获得泡点经验\n2.押送的犯人被攻击会停止3秒钟\n3.犯人被打死会导致押送失败，获得部分奖励\n4.放弃押镖没有任何奖励\n5.劫杀其他行会获得大量掉落\nPS:当你被攻击时，你可以向行会或是好友求助";
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list.array = _loc_3[0];
            list.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = list.array[param2];
            }
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            ModelProxy.change("zone", "paoCheck", -1);
            ModelProxy.change("mainui", "changePao", false);
            return;
        }// end function

        public function initEvent() : void
        {
            txt_oper.addEventListener(MouseEvent.CLICK, this.doQuit);
            btn_trans.clickHandler = new Handler(this.toEms);
            btn_auto.clickHandler = new Handler(this.toqz);
            return;
        }// end function

        private function toqz() : void
        {
            ModelProxy.change("data", "isAutoEms", true);
            ModelProxy.change("zone", "emsAuto", true);
            return;
        }// end function

        private function toEms() : void
        {
            if (this.transTimeDis <= 0)
            {
                UnionSender._62unionEmsJoin();
                this.transTimeDis = 10;
                btn_trans.disabled = true;
                btn_trans.label = "冷却中(" + this.transTimeDis + "秒)";
            }
            return;
        }// end function

        private function timeCheck() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this.transTimeDis - 1;
            _loc_1.transTimeDis = _loc_2;
            if (this.transTimeDis <= 0)
            {
                btn_trans.label = "传送至镖车";
                btn_trans.disabled = false;
            }
            else
            {
                btn_trans.label = "冷却中(" + this.transTimeDis + "秒)";
            }
            var _loc_1:String = this;
            var _loc_2:* = this.qzTimeDis - 1;
            _loc_1.qzTimeDis = _loc_2;
            if (this.qzTimeDis <= 0)
            {
                btn_auto.label = "自动押运";
                btn_auto.disabled = false;
            }
            else
            {
                btn_auto.label = "冷却中(" + this.qzTimeDis + "秒)";
            }
            return;
        }// end function

        protected function doQuit(event:MouseEvent) : void
        {
            var e:* = event;
            Alert2.show("您是否要放弃押运，放弃后将无任何奖励？", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    UnionSender._60giveUpUnionEms();
                }
                return;
            }// end function
            , null, true);
            return;
        }// end function

        public function removeEvent() : void
        {
            txt_oper.removeEventListener(MouseEvent.CLICK, this.doQuit);
            if (this.timer > 0)
            {
                clearInterval(this.timer);
                this.timer = 0;
            }
            return;
        }// end function

    }
}
